<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring3-3.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">

<head th:substituteby="header :: copy"></head>

<body>

	<h1>Exceptions Demo</h1>
	<p>
		Demo running with profiles: <i th:text="${profiles}">profiles</i>
	</p>
	<ul>
		<li th:switch="${#strings.substringBefore(profiles,',')}"><i
			th:text="${#strings.substringBefore(profiles,',')}">FIRST-PROFILE-NAME</i>:
			<span th:case="'global'">Exceptions handled globally using a <code>@ControllerAdvice</code>
				- see <code>GlobalControllerExceptionHandler</code>.
		</span> <span th:case="'controller'">Exceptions handled locally by the
				<code>ExceptionHandlingController</code>.
		</span></li>

		<li th:switch="${#strings.substringAfter(profiles,', ')}"><i
			th:text="${#strings.substringAfter(profiles,', ')}">SECOND-PROFILE-NAME</i>:
			Exceptions not handled elsewhere are <span th:case="'none'">handled
				by container. </span> <span th:case="'java-config'">passed to a <code>SimpleMappingExceptionResolver</code>
				created via Java Configuration - see <code>ExceptionConfiguration</code>.
		</span> <span th:case="'xml-config'">passed to a <code>SimpleMappingExceptionResolver</code>
				created via XML Configuration - see <code>mvc-configuration.xml</code>.
		</span></li>
	</ul>
	<p>
		For details on the different profiles and what they do see <a
			href="https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc#sample-application-and-spring-boot">discussion</a>
		in the Blog.
	</p>

	<p>
		Each of the links below demonstrates one of the exception handling
		techniques discussed in <a
			href="https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc">
			the Blog</a>.
	</p>

	<p>
		By default the exceptions are handled by the controller that raises
		them. To switch to global exception handling using a
		<code>@ControllerAdvice</code>:
		edit
		<code>Main.java</code>
		find the
		<code>global</code>
		data-member and change it from
		<code>false</code>
		to
		<code>true</code>.
		To fully understand this demo, review the output in the server (console) log
		as you click the links below.
	</p>
	<p>
		This demo uses the <a href="http://thymeleaf.org">Thymeleaf</a> view
		generation system to generate HTML pages (it's a nice alternative to
		JSP and configured by Spring Boot automatically).
	</p>
	<p>
		Spring-Boot sets up <i>error</i> view as the default and Thymeleaf supplies
		the corresponding <i>error.html</i> template. Rename <i>error.html</i>
		to <i>error2.html</i> to see the difference.
	</p>
	<p>
		When the <i>xml-config</i> or <i>java-config</i> profiles are enabled
		(instead of <i>none</i>), they setup a
		<code>SimpleMappingExceptionResolver</code>
		and its default error view is used. This can be seen when clicking on
		the <i>unhandledException</i> link. It is not configured by default so:
		edit
		<code>Main.java</code>
		find the
		<code>smerConfig</code>
		data-member and change its value to
		<code>JAVA</code>
		or
		<code>XML</code>.
	</p>

	<ul class="openlist">
		<li>Throw <a href="orderNotFound">OrderNotFoundException</a> -
			should generate a 404.
		</li>
		<li>Throw <a href="dataIntegrityViolation">DataIntegrityViolationException</a>
			- should generate a 409.
		</li>
		<li>Throw <a href="databaseError1">SQLException</a> - should
			return a specific database-error page.
		</li>
		<li>Throw <a href="databaseError2">DataAccessException</a> -
			should also return the database-error page. Demonstrates catching
			multiple exceptions with one handler.
		</li>
		<li>Throw <a href="databaseException">DatabaseException</a> -
			should generate a specific database-error page due to configuration
			of <code>SimpleMappingExceptionResolver</code> (if configured),
			otherwise your container's error page is used.
		</li>
		<li>Throw <a href="invalidCreditCard">InvalidCreditCardException</a>
			- should generate a specific credit-card error page due to
			configuration of <code>SimpleMappingExceptionResolver</code> (if
			configured), otherwise your container's error page is used.
		</li>
		<li>Throw <a href="customException">CustomException</a> - should
			generate a support oriented error page with hidden stack-trace hidden
			in the page source. <i>This is the only page generated using JSP
				(Thymeleaf cannot yet generate dynamic output inside HTML comments -
				planned for V2.1)</i>
		</li>
		<li>Throw <a href="unhandledException">UnhandledException</a> -
			should invoke the default (fall-back) error page defined by <code>SimpleMappingExceptionResolver</code>
			(if configured), otherwise your container's error page is used.
			<p th:if="${#strings.substringAfter(profiles,', ') != 'none'}">
				Note how uninformative it is. Subclass
				<code>SimpleMappingExceptionResolver</code>
				and override its
				<code>getModelAndView()</code>
				method to make additional context available in the model and in the
				error page (see
				<code>ExampleSimpleMappingExceptionResolver</code>
				).
			</p>
		</li>
		<li>A genuinely <a href="unknown">Unknown page</a>. There is no
			handler for this URL, so the framework will generate a 404. (No
			exception handlers do this, this is the standard Spring MVC response
			to a URL it has no handler for).
		</li>
	</ul>

	<h3>Spring Boot URLs</h3>
	<p>For those interested, Spring Boot provides RESTful URLs for
		interogating your application (they return JSON):</p>

	<ul>
		<li><a th:href="@{/beans}">The beans</a></li>
		<li><a th:href="@{/env}">The environment</a></li>
		<li><a th:href="@{/dump}">Thread dump</a></li>
		<li><a th:href="@{/health}">Application health</a></li>
		<li><a th:href="@{/info}">Application information</a></li>
		<li><a th:href="@{/metrics}">Application metrics</a></li>
		<li><a th:href="@{/trace}">Request call trace</a></li>
	</ul>

	<div th:substituteby="footer :: copy"></div>

</body>
</html>
